package com.li.controller;

import com.li.pojo.Member;
import com.li.pojo.ReturnMessage;
import com.li.pojo.User;
import com.li.pojo.WorkDto;
import com.li.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class MemberController {
    @Autowired
    private MemberService memberService;

    @RequestMapping("/selectMembers")
    public ReturnMessage selectMembers(@RequestParam Map<String, String> params){
        System.out.println("查询参数：");
        System.out.println(params);
        ReturnMessage returnMessage = new ReturnMessage();
        List<Member> list = memberService.selectMember(params);
        long count = memberService.count(params);
        returnMessage.setData(list);
        returnMessage.setMsg("获取成员数据成功");
        returnMessage.setOther(count);
        return returnMessage;
    }



    @RequestMapping("/addMember")
    public ReturnMessage MemberAdd(Member member){
        ReturnMessage returnMessage = new ReturnMessage();

        int f = memberService.addMember(member);
        if (f==0){
            returnMessage.setMsg("member已存在");
            returnMessage.setState("400");
            return returnMessage;
        }
        returnMessage.setMsg("成员："+member.getName()+"添加成功!");
        returnMessage.setData(member);
        return returnMessage;
    }
    @RequestMapping("/deleteMembers")
    public ReturnMessage deleteMember(@RequestBody List<Integer> deleteList){
        ReturnMessage returnMessage = new ReturnMessage();
        int f = memberService.deleteMember(deleteList);
        System.out.println("删除");
        System.out.println(deleteList);
        returnMessage.setData(deleteList);
        returnMessage.setMsg("删除成功");
        return returnMessage;
    }
    @RequestMapping("/updateMember")
    public ReturnMessage updateMember(Member member){
        ReturnMessage returnMessage = new ReturnMessage();
        System.out.println("更新:");
        System.out.println(member);
        memberService.updateMember(member);
        returnMessage.setMsg("成员："+member.getName()+"更新成功!");
        returnMessage.setData(member);
        return returnMessage;
    }
}
